import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

///
/// 图片管理类
///
class ImageHelper {
  ///
  /// 获取assets/images文件件下的图片
  ///
  static String wrapImageAssets(String url) {
    return "assets/images/" + url;
  }

  ///
  /// 获取assets/animations文件件下的图片
  ///
  static String wrapAnimationAssets(String url) {
    return "assets/animations/" + url;
  }

  ///
  /// PlaceHolder
  ///
  static Widget placeHolder({double width, double height}) {
    return SizedBox(width: width, height: height, child: CupertinoActivityIndicator(radius: min(10.0, width / 3)));
  }

  ///
  /// 错误图片
  ///
  static Widget error({double width, double height, double size}) {
    return SizedBox(
        width: width,
        height: height,
        child: Icon(
          Icons.error_outline,
          size: size,
        ));
  }

  ///
  /// 随机图片
  ///
  static String randomUrl({int width = 100, int height = 100, Object key = ''}) {
    return 'https://placeimg.com/$width/$height/${key.hashCode.toString() + key.toString()}';
  }
}

class IconFonts {
  IconFonts._();

  /// iconfont:flutter base
  static const String fontFamily = 'iconfont';

  static const IconData pageEmpty = IconData(0xe63c, fontFamily: fontFamily);
  static const IconData pageError = IconData(0xe600, fontFamily: fontFamily);
  static const IconData pageNetworkError = IconData(0xe678, fontFamily: fontFamily);
  static const IconData pageUnAuth = IconData(0xe65f, fontFamily: fontFamily);
}
